package com.travel.server.manager.impl.command.message;

import com.travel.common.CommonConstant;
import com.travel.server.manager.dto.request.message.QueryMessageMsgDetailRequest;
import com.travel.server.manager.dto.response.message.QueryMessageMsgDetailResponse;
import com.travel.server.manager.impl.command.AbstractCommand;
import com.travel.server.manager.impl.dal.MessageDal;
import com.travel.server.manager.model.MessageTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: LiZhenhui
 * @Date: 2018\11\17 0017 16:24
 * @Desc:
 */
@Component
@Slf4j
public class QueryMessageMsgDetailCommand extends AbstractCommand<QueryMessageMsgDetailRequest, QueryMessageMsgDetailResponse> {

    @Autowired
    private MessageDal messageDal;

    @Override
    protected void checkInput(QueryMessageMsgDetailRequest request) {
        if(request.getId() == null){
            throwInvalidParam();
        }
    }

    @Override
    public QueryMessageMsgDetailResponse handle(QueryMessageMsgDetailRequest request) {
        checkInput(request);
        MessageTemplate messageTemplate = messageDal.selectById(request.getId());
        QueryMessageMsgDetailResponse response = new QueryMessageMsgDetailResponse();
        response.setContent(messageTemplate.getMessageContent());
        response.setType(messageTemplate.getSmsTemplateType() + CommonConstant.EMPTY_STR);
        response.setName(messageTemplate.getMessageTitle());
        response.setSign(messageTemplate.getMessageSign());

        return response;
    }
}
